/**
 * @(#)ApkConfigController.java 2017年03月1日
 * Copyright(C) 2017 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.domian.MiguReadSearchVo;
import org.jsbd.boss.service.IMiguReadSearchService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import org.jsbd.boss.util.DateUtil;


@Controller
@RequestMapping("/miguReadSearch")
public class MiguReadSearchController{
	
	@Resource
	private IMiguReadSearchService miguReadSearchService;

	/**
	 * 新增执行情况页面
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "newTaskExecList")
	public String newTaskExecList(Model model) throws Exception {
		return "/miguReadSearch/newTaskExecList";
	}
	
	/**
	 * 新增执行情况数据
	 * 
	 * @param page
	 * @param miguReadSearchVo 查询条件
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "newTaskExecListJson")
	@ResponseBody
	public Map<String, Object> newTaskExecListJson(DataGridModel page, MiguReadSearchVo miguReadSearchVo) throws Exception {
		String startTime = miguReadSearchVo.getStartTime();
		String endTime = miguReadSearchVo.getEndTime();
		if (StringUtils.isNotBlank(startTime)) {
			miguReadSearchVo.setStartTime(startTime.replaceAll("-", ""));
		}
		if (StringUtils.isNotBlank(endTime)) {
			miguReadSearchVo.setEndTime(endTime.replaceAll("-", ""));
		}
		
		String sname = miguReadSearchVo.getSname();
		if (StringUtils.isNotBlank(sname)) {
			String[] snames = sname.split(" ");
			List<String> keywords = new ArrayList<>();
			for (String keyword : snames) {
				keywords.add(keyword);
			}
			miguReadSearchVo.setKeywords(keywords);
		}
		return miguReadSearchService.getNewTaskExecListPage(page, miguReadSearchVo);
	}
	
	/**
	 * 留存执行情况页面
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "retentTaskExecList")
	public String retentTaskExecList(Model model) throws Exception {
		return "/miguReadSearch/retentTaskExecList";
	}
	
	/**
	 * 留存执行情况数据
	 * 
	 * @param page
	 * @param miguReadConfig 查询条件
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "retentTaskExecListJson")
	@ResponseBody
	public Map<String, Object> retentTaskExecListJson(DataGridModel page, MiguReadSearchVo miguReadSearchVo) throws Exception {
		String startTime = miguReadSearchVo.getStartTime();
		String endTime = miguReadSearchVo.getEndTime();
		
		String nowDate = DateUtil.getCurrentDateStr();
		
		miguReadSearchVo.setStartTime(StringUtils.isBlank(startTime)?nowDate:startTime.replaceAll("-", ""));
		miguReadSearchVo.setEndTime(StringUtils.isBlank(endTime)?nowDate:endTime.replaceAll("-", ""));
		
		String sname = miguReadSearchVo.getSname();
		if (StringUtils.isNotBlank(sname)) {
			String[] snames = sname.split(" ");
			List<String> keywords = new ArrayList<>();
			for (String keyword : snames) {
				keywords.add(keyword);
			}
			miguReadSearchVo.setKeywords(keywords);
		}
		
		Map<String, Object> map = miguReadSearchService.getRetentTaskExecList(miguReadSearchVo);
		return map;
	}
	

}
